package net;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class PoolExecutor {
    private static final int AVAILABLE_PROCESSORS = Runtime.getRuntime().availableProcessors();

    private static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
            AVAILABLE_PROCESSORS,  //核心线程数
            4 * AVAILABLE_PROCESSORS,  //最大线程数
            5, TimeUnit.SECONDS,  //keepAliveTime
            new LinkedBlockingDeque<>(50));  //阻塞队列

    static {
        threadPoolExecutor.prestartCoreThread();
    }

    public static ThreadPoolExecutor executor()
    {
        return threadPoolExecutor;
    }
}
